package com.qf.hospital.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.hospital.entity.Pharmacy;
import com.qf.hospital.mapper.PharmacyMapper;
import com.qf.hospital.service.PharmacyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zjw
 * @description
 * @date 2021/10/21 10:38
 */
@Service
public class PharmacyServiceImpl implements PharmacyService {

    @Autowired
    private PharmacyMapper pharmacyMapper;

    @Override
    public PageInfo<Pharmacy> selectDrug(String drugname, Integer page, Integer limit) {
        //1. 分页
        PageHelper.startPage(page,limit);
        //2. 查询
        List<Pharmacy> list = pharmacyMapper.selectDrug(drugname);
        //3. 封装
        PageInfo<Pharmacy> pageInfo = new PageInfo<>(list);
        //4. 返回
        return pageInfo;
    }

    @Override
    public int happyLockUpdate(Pharmacy pharmacy) {
        return 0;
    }

    @Override
    public int unhappyLockUpdate(Pharmacy pharmacy) {
        Pharmacy info = pharmacyMapper.selectForUpdate(pharmacy.getPharmacyId());

        int i = pharmacyMapper.updateByPrimaryKeySelective(pharmacy);

        return 0;
    }


}
